package mp.weixin.WXpublic.send;

import mp.weixin.WXpublic.BaseReceiveMessage;
import mp.weixin.WXpublic.BaseSendMessage;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;


public class SMusicEntity extends BaseSendMessage {

    private String title;
    private String description;
    private String musicURL;
    private String hQMusicUrl;
    private String mediaId;
    private String thumbMediaId;
    private long msgId;

    public SMusicEntity(BaseReceiveMessage brm, String title, String description, String musicURL, String hQMusicUrl, String mediaId, String thumbMediaId, long msgId) {
        super(brm);
        this.title = title;
        this.description = description;
        this.musicURL = musicURL;
        this.hQMusicUrl = hQMusicUrl;
        this.mediaId = mediaId;
        this.thumbMediaId = thumbMediaId;
        this.msgId = msgId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMusicURL() {
        return musicURL;
    }

    public void setMusicURL(String musicURL) {
        this.musicURL = musicURL;
    }

    public String getHQMusicUrl() {
        return hQMusicUrl;
    }

    public void setHQMusicUrl(String hQMusicUrl) {
        this.hQMusicUrl = hQMusicUrl;
    }

    public long getMsgId() {
        return msgId;
    }

    public void setMsgId(long msgId) {
        this.msgId = msgId;
    }

    @Override
    public SendTypeEnum getMsgType() {
        return SendTypeEnum.MUSIC;
    }

    public String getMediaId() {
        return mediaId;
    }

    public void setMediaId(String mediaId) {
        this.mediaId = mediaId;
    }

    public String getThumbMediaId() {
        return thumbMediaId;
    }

    public void setThumbMediaId(String thumbMediaId) {
        this.thumbMediaId = thumbMediaId;
    }

    @Override
    public String toWeiXinMessageXMLString() {
        /**
         * <xml>
         * <ToUserName><![CDATA[toUser]]></ToUserName>
         * <FromUserName><![CDATA[fromUser]]></FromUserName>
         * <CreateTime>12345678</CreateTime>
         * <MsgType><![CDATA[music]]></MsgType>
         * <Music>
         * <Title><![CDATA[TITLE]]></Title>
         * <Description><![CDATA[DESCRIPTION]]></Description>
         * <MusicUrl><![CDATA[MUSIC_Url]]></MusicUrl>
         * <HQMusicUrl><![CDATA[HQ_MUSIC_Url]]></HQMusicUrl>
         * <ThumbMediaId><![CDATA[media_id]]></ThumbMediaId>
         * </Music>
         * </xml>
         */
//        StringBuilder xmlStr = new StringBuilder();
//        xmlStr.append("<xml>");
//        xmlStr.append("<ToUserName><![CDATA[").append(this.getToUserName()).append("]]></ToUserName>");
//        xmlStr.append("<FromUserName><![CDATA[").append(this.getFromUserName()).append("]]></FromUserName>");
//        xmlStr.append("<CreateTime>").append(this.getCreateTime().getTime()).append("</CreateTime>");
//        xmlStr.append("<MsgType><![CDATA[").append(this.getMsgType().getType()).append("]]></MsgType>");
//        xmlStr.append("<Music>");
//        xmlStr.append("<Title><![CDATA[").append(this.getTitle()).append("]]></Title>");
//        xmlStr.append("<Description><![CDATA[").append(this.getDescription()).append("]]></Description>");
//        xmlStr.append("<MusicUrl><![CDATA[").append(this.getMusicURL()).append("]]></MusicUrl>");
//        xmlStr.append("<HQMusicUrl><![CDATA[").append(this.getHQMusicUrl()).append("]]></HQMusicUrl>");
//        xmlStr.append("<ThumbMediaId><![CDATA[").append(this.getThumbMediaId()).append("]]></ThumbMediaId>");
//        xmlStr.append("</Music>");
//        xmlStr.append("</xml>");
//        return xmlStr.toString();
        String returnStr = "";
        Document doc = DocumentHelper.createDocument();
        Element rootXML = doc.addElement("xml");
        rootXML.addElement("ToUserName").setText(this.getToUserName());
        rootXML.addElement("FromUserName").setText(this.getFromUserName());
        rootXML.addElement("CreateTime").setText(this.getCreateTime().getTime() + "");
        rootXML.addElement("MsgType").setText(this.getMsgType().getType());
        Element el = rootXML.addElement("Music");
        el.addElement("Title").setText(this.getTitle());
        el.addElement("Description").setText(this.getDescription());
        el.addElement("MusicUrl").setText(this.getMusicURL());
        el.addElement("HQMusicUrl").setText(this.getHQMusicUrl());
        el.addElement("ThumbMediaId").setText(this.getThumbMediaId());
        returnStr = rootXML.asXML();
        return returnStr;
    }

}
